logo

Crate magma

source · []
Expand description

Pure Rust implementation of the Magma block cipher defined in GOST 28147-89 and GOST R 34.12-2015.

⚠️ Security Warning: Hazmat!

This crate implements only the low-level block cipher function, and is intended for use for implementing higher-level constructions only. It is NOT intended for direct use in applications.

USE AT YOUR OWN RISK!

Examples

use magma::Magma;
use magma::cipher::{
    generic_array::GenericArray,
    BlockEncrypt, BlockDecrypt, KeyInit,
};
use hex_literal::hex;

// Example vector from GOST 34.12-2018
let key = hex!(
    "FFEEDDCCBBAA99887766554433221100"
    "F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF"
);
let plaintext = hex!("FEDCBA9876543210");
let ciphertext = hex!("4EE901E5C2D8CA3D");

let cipher = Magma::new(&key.into());

let mut block = GenericArray::clone_from_slice(&plaintext);
cipher.encrypt_block(&mut block);
assert_eq!(&ciphertext, block.as_slice());

cipher.decrypt_block(&mut block);
assert_eq!(&plaintext, block.as_slice());

Re-exports

pub use cipher;

Structs

Block cipher defined in GOST 28147-89 generic over S-box

Traits

Trait implemented for the GOST 28147-89 cipher S-boxes.

Type Definitions

Block cipher defined in GOST 28147-89 with CryptoPro S-box version A

Block cipher defined in GOST 28147-89 with CryptoPro S-box version B

Block cipher defined in GOST 28147-89 with CryptoPro S-box version C

Block cipher defined in GOST 28147-89 with CryptoPro S-box version D

Block cipher defined in GOST 28147-89 with test S-box

Block cipher defined in GOST R 34.12-2015 (Magma)